package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.junit.Test

import org.junit.Assert.*
import org.slf4j.LoggerFactory

class MainActiveOnlineDataTest {

    @Test
    fun fillSet() {
        val buf = Unpooled.buffer()
        MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.SetActiveOnline
            data = MainSetActiveOnlineData(3).also {
                it.activeList = byteArrayOf(10, 15)
            }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("set active-online", DEMO_SET_ACTIVE_ONLINE, str)
    }

    @Test
    fun fillAsk() {
        val buf = Unpooled.buffer()
        MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskActiveOnline
            data = MainAskActiveOnlineData()

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask active-online", DEMO_ASK_ACTIVE_ONLINE, str)
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MainActiveOnlineDataTest::class.java)

        const val DEMO_SET_ACTIVE_ONLINE = "68120000013803020a0f2f16"

        const val DEMO_ASK_ACTIVE_ONLINE = "681200000139004c16"
    }
}